package com.lhj.bootdemo.thread.threadlocal;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author lhj
 * @version 1.0
 * @date 2022/5/25 2:35 下午
 * @description:
 */

public class ThreadLocalTest {

    private static ExecutorService service = Executors.newCachedThreadPool();
    static ThreadLocal<Boolean> threadLocal = new ThreadLocal<>();
    public static void main(String[] args) {
        threadLocal.set(Boolean.TRUE);
        service.execute(() -> {
            threadLocal.set(Boolean.FALSE);
            System.out.println("子线程设置为：" + threadLocal.get());
        });
        System.out.println("主线程设置为：" + threadLocal.get());
        service.shutdown();
    }
}
